{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Short-Circuit Calculation according to IEC 60909\n",
    "\n",
    "pandapower supports short-circuit calculations with the method of equivalent voltage source at the fault location according to IEC 60909. The pandapower short-circuit calculation supports the following elements:\n",
    "\n",
    "- sgen (as motor or as full converter generator)\n",
    "- gen (as synchronous generator)\n",
    "- ext_grid\n",
    "- line\n",
    "- trafo\n",
    "- trafo3w\n",
    "- impedance\n",
    "\n",
    "with the correction factors as defined in IEC 60909. Loads and shunts are neglected as per standard. The pandapower switch model is fully integrated into the short-circuit calculation. \n",
    "\n",
    "The following short-circuit currents can be calculated:\n",
    "- ikss (Initial symmetrical short-circuit current)\n",
    "- ip (short-circuit current peak)\n",
    "- ith (equivalent thermal short-circuit current)\n",
    "\n",
    "either as\n",
    "\n",
    " - symmetrical three-phase or\n",
    " - asymmetrical two-phase\n",
    " \n",
    "short circuit current. Calculations are available for meshed as well as for radial networks. ip and ith are only implemented for short circuits far from synchronous generators.\n",
    "\n",
    "The results for all elements and different short-circuit currents are tested against commercial software to ensure that correction factors are correctly applied. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Example Network\n",
    "\n",
    "Here is a little example on how to use the short-circuit calculation. First, we create a simple open ring network with 4 buses, that are connected by one transformer and two lines with one open sectioning point. The network is fed by an external grid connection at bus 1:\n",
    "\n",
    "<img src=\"shortcircuit/example_network_sc.png\">"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandapower as pp\n",
    "import pandapower.shortcircuit as sc\n",
    "\n",
    "def ring_network():\n",
    "    net = pp.create_empty_network()\n",
    "    b1 = pp.create_bus(net, 220)\n",
    "    b2 = pp.create_bus(net, 110)\n",
    "    b3 = pp.create_bus(net, 110)\n",
    "    b4 = pp.create_bus(net, 110)\n",
    "    pp.create_ext_grid(net, b1, s_sc_max_mva=100., s_sc_min_mva=80., rx_min=0.20, rx_max=0.35)\n",
    "    pp.create_transformer(net, b1, b2, \"100 MVA 220/110 kV\")\n",
    "    pp.create_line(net, b2, b3, std_type=\"N2XS(FL)2Y 1x120 RM/35 64/110 kV\" , length_km=15.)\n",
    "    l2 = pp.create_line(net, b3, b4, std_type=\"N2XS(FL)2Y 1x120 RM/35 64/110 kV\" , length_km=12.)\n",
    "    pp.create_line(net, b4, b2, std_type=\"N2XS(FL)2Y 1x120 RM/35 64/110 kV\" , length_km=10.)\n",
    "    pp.create_switch(net, b4, l2, closed=False, et=\"l\")\n",
    "    return net"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Symmetric Short-Circuit Calculation\n",
    "\n",
    "### Maximum Short Circuit Currents\n",
    "Now, we load the network and calculate the maximum short-circuit currents with the calc_sc function:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "tazan.pandapower.shortcircuit.calc_sc - WARNING: Branch results are in beta mode and might not always be reliable, especially for transformers\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ikss_ka</th>\n",
       "      <th>ip_ka</th>\n",
       "      <th>ith_ka</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0.262432</td>\n",
       "      <td>0.505834</td>\n",
       "      <td>0.263723</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0.476454</td>\n",
       "      <td>0.942589</td>\n",
       "      <td>0.479039</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0.466671</td>\n",
       "      <td>0.915418</td>\n",
       "      <td>0.469123</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0.469892</td>\n",
       "      <td>0.924301</td>\n",
       "      <td>0.472386</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    ikss_ka     ip_ka    ith_ka\n",
       "0  0.262432  0.505834  0.263723\n",
       "1  0.476454  0.942589  0.479039\n",
       "2  0.466671  0.915418  0.469123\n",
       "3  0.469892  0.924301  0.472386"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "net = ring_network()\n",
    "sc.calc_sc(net, case=\"max\", ip=True, ith=True, branch_results=True)\n",
    "net.res_bus_sc"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "where ikss is the initial short-circuit current, ip is the peak short-circuit current and ith is the thermal equivalent current.\n",
    "\n",
    "For branches, the results are defined as the maximum current flows through that occurs for a fault at any bus in the network. The results are available seperately for lines:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ikss_ka</th>\n",
       "      <th>ip_ka</th>\n",
       "      <th>ith_ka</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0.466671</td>\n",
       "      <td>0.915418</td>\n",
       "      <td>0.469123</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0.459100</td>\n",
       "      <td>0.894771</td>\n",
       "      <td>0.461455</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0.469892</td>\n",
       "      <td>0.924301</td>\n",
       "      <td>0.472386</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    ikss_ka     ip_ka    ith_ka\n",
       "0  0.466671  0.915418  0.469123\n",
       "1  0.459100  0.894771  0.461455\n",
       "2  0.469892  0.924301  0.472386"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "net.res_line_sc"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "and transformers:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ikss_hv_ka</th>\n",
       "      <th>ikss_lv_ka</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0.238227</td>\n",
       "      <td>0.476454</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   ikss_hv_ka  ikss_lv_ka\n",
       "0    0.238227    0.476454"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "net.res_trafo_sc"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Minimum Short Circuit Currents"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Minimum short-circuits can be calculated in the same way. However, we need to specify the end temperature of the lines after a fault as per standard first:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "tazan.pandapower.shortcircuit.calc_sc - WARNING: Branch results are in beta mode and might not always be reliable, especially for transformers\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ikss_ka</th>\n",
       "      <th>ip_ka</th>\n",
       "      <th>ith_ka</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0.209946</td>\n",
       "      <td>0.462534</td>\n",
       "      <td>0.211736</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0.384422</td>\n",
       "      <td>0.860874</td>\n",
       "      <td>0.387974</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0.377608</td>\n",
       "      <td>0.832832</td>\n",
       "      <td>0.380846</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0.379861</td>\n",
       "      <td>0.841982</td>\n",
       "      <td>0.383197</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    ikss_ka     ip_ka    ith_ka\n",
       "0  0.209946  0.462534  0.211736\n",
       "1  0.384422  0.860874  0.387974\n",
       "2  0.377608  0.832832  0.380846\n",
       "3  0.379861  0.841982  0.383197"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "net = ring_network()\n",
    "net.line[\"endtemp_degree\"] = 80\n",
    "sc.calc_sc(net, case=\"min\", ith=True, ip=True, branch_results=True)\n",
    "net.res_bus_sc"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The branch results are now the minimum current flows through each branch:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ikss_ka</th>\n",
       "      <th>ip_ka</th>\n",
       "      <th>ith_ka</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0.372278</td>\n",
       "      <td>0.811639</td>\n",
       "      <td>0.375302</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0.372278</td>\n",
       "      <td>0.811639</td>\n",
       "      <td>0.375302</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0.379861</td>\n",
       "      <td>0.841982</td>\n",
       "      <td>0.383197</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    ikss_ka     ip_ka    ith_ka\n",
       "0  0.372278  0.811639  0.375302\n",
       "1  0.372278  0.811639  0.375302\n",
       "2  0.379861  0.841982  0.383197"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "net.res_line_sc"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ikss_hv_ka</th>\n",
       "      <th>ikss_lv_ka</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0.186139</td>\n",
       "      <td>0.372278</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   ikss_hv_ka  ikss_lv_ka\n",
       "0    0.186139    0.372278"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "net.res_trafo_sc"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Asynchronous Motors\n",
    "\n",
    "Asynchronous motors can be specified by creating a static generator of type \"motor\". For the short circuit impedance, an R/X ratio \"rx\" as well as the ratio between nominal current and short circuit current \"k\" has to be specified:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "This pandapower network includes the following parameter tables:\n",
       "   - bus (4 elements)\n",
       "   - sgen (1 element)\n",
       "   - switch (1 element)\n",
       "   - ext_grid (1 element)\n",
       "   - line (3 elements)\n",
       "   - trafo (1 element)"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "net = ring_network()\n",
    "pp.create_sgen(net, 2, p_mw=0, sn_mva=0.5, k=1.2, rx=7., type=\"motor\")\n",
    "net"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "If we run the short-circuit calculation again, we can see that the currents increased due to the contribution of the inverteres to the short-circuit currents."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ikss_ka</th>\n",
       "      <th>ip_ka</th>\n",
       "      <th>ith_ka</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0.264007</td>\n",
       "      <td>0.508062</td>\n",
       "      <td>0.265307</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0.479604</td>\n",
       "      <td>0.947044</td>\n",
       "      <td>0.482207</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0.469822</td>\n",
       "      <td>0.919873</td>\n",
       "      <td>0.472290</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0.472999</td>\n",
       "      <td>0.928695</td>\n",
       "      <td>0.475510</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    ikss_ka     ip_ka    ith_ka\n",
       "0  0.264007  0.508062  0.265307\n",
       "1  0.479604  0.947044  0.482207\n",
       "2  0.469822  0.919873  0.472290\n",
       "3  0.472999  0.928695  0.475510"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sc.calc_sc(net, case=\"max\", ith=True, ip=True)\n",
    "net.res_bus_sc"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Synchronous Generators\n",
    "\n",
    "Synchronous generators can also be considered in the short-circuit calculation with the gen element. According to the standard, the rated power factor (cos$\\varphi$) \"cos_phi\", rated voltage \"vn_kv\", rated apparent power \"sn_kva\" and subtransient resistance \"rdss\" and reactance \"xdss\" are necessary to calculate the short circuit impedance:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "This pandapower network includes the following parameter tables:\n",
       "   - bus (4 elements)\n",
       "   - gen (1 element)\n",
       "   - switch (1 element)\n",
       "   - ext_grid (1 element)\n",
       "   - line (3 elements)\n",
       "   - trafo (1 element)"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "net = ring_network()\n",
    "pp.create_gen(net, 2, p_mw=0, vm_pu=1.0, cos_phi=0.8, vn_kv=22, sn_mva=5, xdss_pu=0.2, rdss_pu=0.005)\n",
    "net"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "and run the short-circuit calculation again:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "tazan.pandapower.shortcircuit.calc_sc - WARNING: aperiodic and thermal short-circuit currents are only implemented for faults far from generators!\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ikss_ka</th>\n",
       "      <th>ip_ka</th>\n",
       "      <th>ith_ka</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0.265319</td>\n",
       "      <td>0.513780</td>\n",
       "      <td>0.266647</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0.482287</td>\n",
       "      <td>0.958532</td>\n",
       "      <td>0.484950</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0.472489</td>\n",
       "      <td>0.931356</td>\n",
       "      <td>0.475018</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0.475575</td>\n",
       "      <td>0.939648</td>\n",
       "      <td>0.478143</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    ikss_ka     ip_ka    ith_ka\n",
       "0  0.265319  0.513780  0.266647\n",
       "1  0.482287  0.958532  0.484950\n",
       "2  0.472489  0.931356  0.475018\n",
       "3  0.475575  0.939648  0.478143"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sc.calc_sc(net, case=\"max\", ith=True, ip=True)\n",
    "net.res_bus_sc"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Once again, the short-circuit current increases due to the contribution of the generator. As can be seen in the warning, the values for peak and thermal equivalent short-circuit current will only be accurate for faults far from generators."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Meshed Networks\n",
    "\n",
    "The correction factors for aperiodic and thermal currents differ between meshed and radial networks. pandapower includes a meshing detection that automatically detects the meshing for each short-circuit location. Alternatively, the topology can be set to \"radial\" or \"meshed\" to circumvent the check and save calculation time.\n",
    "\n",
    "We load the radial network and close the open sectioning point to get a closed ring network:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ikss_ka</th>\n",
       "      <th>ip_ka</th>\n",
       "      <th>ith_ka</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0.262432</td>\n",
       "      <td>0.505834</td>\n",
       "      <td>0.263723</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0.476454</td>\n",
       "      <td>0.942589</td>\n",
       "      <td>0.479039</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0.470593</td>\n",
       "      <td>0.926244</td>\n",
       "      <td>0.473098</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0.471649</td>\n",
       "      <td>0.929174</td>\n",
       "      <td>0.474168</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    ikss_ka     ip_ka    ith_ka\n",
       "0  0.262432  0.505834  0.263723\n",
       "1  0.476454  0.942589  0.479039\n",
       "2  0.470593  0.926244  0.473098\n",
       "3  0.471649  0.929174  0.474168"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "net = ring_network()\n",
    "net.switch.closed = True\n",
    "sc.calc_sc(net, topology=\"auto\", ip=True, ith=True)\n",
    "net.res_bus_sc"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "the network is automatically detected to be meshed and application factors are applied. This can be validated by setting the topology to radial and comparing the results:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ikss_ka</th>\n",
       "      <th>ip_ka</th>\n",
       "      <th>ith_ka</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0.262432</td>\n",
       "      <td>0.505834</td>\n",
       "      <td>0.263723</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0.476454</td>\n",
       "      <td>0.942589</td>\n",
       "      <td>0.479039</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0.470593</td>\n",
       "      <td>0.926244</td>\n",
       "      <td>0.473098</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0.471649</td>\n",
       "      <td>0.929174</td>\n",
       "      <td>0.474168</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    ikss_ka     ip_ka    ith_ka\n",
       "0  0.262432  0.505834  0.263723\n",
       "1  0.476454  0.942589  0.479039\n",
       "2  0.470593  0.926244  0.473098\n",
       "3  0.471649  0.929174  0.474168"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sc.calc_sc(net, topology=\"radial\", ip=True, ith=True)\n",
    "net.res_bus_sc"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "If we look at the line results, we can see that the line currents are significantly smaller than the bus currents:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "tazan.pandapower.shortcircuit.calc_sc - WARNING: Branch results are in beta mode and might not always be reliable, especially for transformers\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ikss_ka</th>\n",
       "      <th>ip_ka</th>\n",
       "      <th>ith_ka</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0.279812</td>\n",
       "      <td>0.550740</td>\n",
       "      <td>0.281301</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0.190781</td>\n",
       "      <td>0.375504</td>\n",
       "      <td>0.191796</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0.344176</td>\n",
       "      <td>0.678046</td>\n",
       "      <td>0.346014</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    ikss_ka     ip_ka    ith_ka\n",
       "0  0.279812  0.550740  0.281301\n",
       "1  0.190781  0.375504  0.191796\n",
       "2  0.344176  0.678046  0.346014"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sc.calc_sc(net, topology=\"auto\", ip=True, ith=True, branch_results=True)\n",
    "net.res_line_sc"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "this is because the short-circuit current is split up on both paths of the ring, which is correctly considered by pandapower."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Fault Impedance\n",
    "\n",
    "It is also possible to specify a fault impedance in the short-circuit calculation:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "net = ring_network()\n",
    "sc.calc_sc(net, topology=\"radial\", ip=True, ith=True, r_fault_ohm=1., x_fault_ohm=2.)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "which of course decreases the short-circuit currents:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ikss_ka</th>\n",
       "      <th>ip_ka</th>\n",
       "      <th>ith_ka</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0.261343</td>\n",
       "      <td>0.503509</td>\n",
       "      <td>0.262627</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0.469382</td>\n",
       "      <td>0.926656</td>\n",
       "      <td>0.471909</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0.459875</td>\n",
       "      <td>0.900379</td>\n",
       "      <td>0.462274</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0.463005</td>\n",
       "      <td>0.908972</td>\n",
       "      <td>0.465446</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    ikss_ka     ip_ka    ith_ka\n",
       "0  0.261343  0.503509  0.262627\n",
       "1  0.469382  0.926656  0.471909\n",
       "2  0.459875  0.900379  0.462274\n",
       "3  0.463005  0.908972  0.465446"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "net.res_bus_sc"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Asymetrical Two-Phase Short-Circuit Calculation\n",
    "\n",
    "All calculations above can be carried out for a two-phase short-circuit current in the same way by specifying \"2ph\" in the fault parameter:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ikss_ka</th>\n",
       "      <th>ip_ka</th>\n",
       "      <th>ith_ka</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0.227273</td>\n",
       "      <td>0.438065</td>\n",
       "      <td>0.228391</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0.412621</td>\n",
       "      <td>0.816306</td>\n",
       "      <td>0.414860</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0.404149</td>\n",
       "      <td>0.792775</td>\n",
       "      <td>0.406272</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0.406938</td>\n",
       "      <td>0.800468</td>\n",
       "      <td>0.409099</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    ikss_ka     ip_ka    ith_ka\n",
       "0  0.227273  0.438065  0.228391\n",
       "1  0.412621  0.816306  0.414860\n",
       "2  0.404149  0.792775  0.406272\n",
       "3  0.406938  0.800468  0.409099"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "net = ring_network()\n",
    "sc.calc_sc(net, fault=\"2ph\", ip=True, ith=True)\n",
    "net.res_bus_sc"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Two phase short-circuits are often used for minimum short-circuit calculations:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ikss_ka</th>\n",
       "      <th>ip_ka</th>\n",
       "      <th>ith_ka</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0.181818</td>\n",
       "      <td>0.400566</td>\n",
       "      <td>0.183369</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0.332920</td>\n",
       "      <td>0.745538</td>\n",
       "      <td>0.335995</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0.326772</td>\n",
       "      <td>0.717815</td>\n",
       "      <td>0.329521</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0.328807</td>\n",
       "      <td>0.726834</td>\n",
       "      <td>0.331657</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    ikss_ka     ip_ka    ith_ka\n",
       "0  0.181818  0.400566  0.183369\n",
       "1  0.332920  0.745538  0.335995\n",
       "2  0.326772  0.717815  0.329521\n",
       "3  0.328807  0.726834  0.331657"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "net = ring_network()\n",
    "net.line[\"endtemp_degree\"] = 150\n",
    "sc.calc_sc(net, fault=\"2ph\", case=\"min\", ip=True, ith=True)\n",
    "net.res_bus_sc"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Single Phase Short-Circuit Calculation\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "pandapower can also calculate single phase short-circuits. The ground fault however depends on the zero-sequence parameters of the network, which have to be added in order to calculate a single line to ground fault:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {},
   "outputs": [],
   "source": [
    "net = ring_network()\n",
    "\n",
    "#r/x ratio in zero sequence parameters\n",
    "net.ext_grid[\"r0x0_max\"] = 0.4\n",
    "net.ext_grid[\"x0x_max\"] = 1.0\n",
    "\n",
    "#zero sequence line parameters\n",
    "net.line[\"r0_ohm_per_km\"] = 0.244\n",
    "net.line[\"x0_ohm_per_km\"] = 0.336\n",
    "net.line[\"c0_nf_per_km\"] = 2000\n",
    "\n",
    "#transformer vector group, zero sequence short circuit voltage\n",
    "#and zero sequence magnetizing impedance\n",
    "net.trafo[\"vector_group\"] = \"Dyn\"\n",
    "net.trafo[\"vk0_percent\"] = 5.\n",
    "net.trafo[\"vkr0_percent\"] = 0.4\n",
    "net.trafo[\"mag0_percent\"] = 10\n",
    "net.trafo[\"mag0_rx\"] = 0.4\n",
    "net.trafo[\"si0_hv_partial\"] = 0.9"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {},
   "outputs": [],
   "source": [
    "sc.calc_sc(net, fault=\"1ph\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ikss_ka</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0.261047</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0.698664</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0.668867</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0.680010</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    ikss_ka\n",
       "0  0.261047\n",
       "1  0.698664\n",
       "2  0.668867\n",
       "3  0.680010"
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "net.res_bus_sc"
   ]
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
